import { deleteCetegory } from '@/api/goods/index';
import { message } from 'ant-design-vue';
import table from './dataTables';
import { useI18n } from 'vue-i18n';

// 删除用户
export default function deleteDataId() {
    const { tableQuery, getCetegoryData, selectedRowKeys } = table;
    const { t } = useI18n();
    const resetTable = () => {
        selectedRowKeys.value = [];
        const timer = window.setTimeout(() => {
            tableQuery.page = 0;
            getCetegoryData(tableQuery);
            clearTimeout(timer);
        }, 1000);
    };
    const handleDelete = (id: number | string) => {
        deleteCetegory([id]).then(() => {
            message.success(t('yl.deleteSuccess'));
            resetTable();
        });
    };
    const handleMultiDelete = () => {
        if (!selectedRowKeys.value.length) {
            return message.warning(t('yl.emptyDeleteConfirm'));
        }
        deleteCetegory(selectedRowKeys.value).then(() => {
            message.success(t('yl.deleteSuccess'));
            resetTable();
        });
    };
    return {
        handleDelete,
        handleMultiDelete,
    };
}
